#include<bits/stdc++.h>
using namespace std;
#define add(x,y) edge[++tail]={head[x],y};head[x]=tail;
struct dd{
    int ne,to,w;
}edge[222222];
int head[111111],tail,n,sum[111111],num[]={3,2,5,2},xx[111111],yy[111111];
void dfs(int t,int fa,int x){
    for(int i=head[t];i;i=edge[i].ne){
        if(edge[i].to!=fa){
            edge[i].w=num[x];
            dfs(edge[i].to,t,(x+1)%4);
        }
    }
}
void solve(){
    cin>>n;
    memset(head,0,sizeof(head));
    memset(sum,0,sizeof(sum));
    memset(edge,0,sizeof(edge));
    tail=0;
    for(int i=1;i<n;i++){
        cin>>xx[i]>>yy[i];
        add(xx[i],yy[i]);add(yy[i],xx[i]);
        sum[xx[i]]++;sum[yy[i]]++;
    }
    int pd=0,pos;
    for(int i=1;i<=n;i++)
        if(sum[i]>2){cout<<-1<<"\n";return;}
        else if(sum[i]<2){pd++;pos=i;}
    if(pd!=2){cout<<-1<<"\n";return;}
    dfs(pos,pos,0);
    for(int j=1;j<n;j++){
        int t=xx[j];
        pd=0;
        for(int i=head[t];i;i=edge[i].ne){
            if(edge[i].to==yy[j]&&edge[i].w)
                {cout<<edge[i].w<<" ";pd=1;break;}
        }
        if(pd)continue;
        t=yy[j];
        for(int i=head[t];i;i=edge[i].ne){
            if(edge[i].to==xx[j]&&edge[i].w)
                {cout<<edge[i].w<<" ";break;}
        }
    }
    cout<<"\n";
}
int main () {
    ios::sync_with_stdio(false);
    int t;
    cin>>t;
    while(t--)solve();
}